<template>
      <div class="remain_t_b_d" v-show="addProcessedShow" @click.stop.prevent="">
    <div class="remain_t_h">
      {{
          remindStatus == 0
            ? "添加到待办"
            : remindStatus == 1
            ? "更改提醒时间"
            : "待办内容"
        }}
    </div>
    <div class="remain_t_m" id="focusState">
      <div class="remain_text" v-html="processedItem.value || processedItem.VALUE"></div>
      <el-date-picker :open="timeOpen" :default-value="new Date()" prefix-icon="none" v-model="processedTime" value-format="yyyy-MM-dd HH:mm:ss" size="mini" type="datetime" @change="timeHandleChange"
        placeholder="选择日程提醒时间" class="dxTime">
      </el-date-picker>
      <div @click="timeHandleClick" style="padding: 10px 0; cursor: pointer">
        <div v-if="processedTime === ''" style="display: flex">
          <img style="margin-right: 10px" src="static/image/home/add_processed.png" />添加日程提醒
        </div>
        <div v-else style="display: flex">
          <img style="margin-right: 10px" src="static/image/home/processed_time.png" />{{ processedTime }}
        </div>
      </div>
      <!-- <Date-picker
				style="flex:1;"
				placement="top-start"
				:open="timeOpen"
				:value="processedTime"
				type="datetime"
				placeholder="选择日程提醒时间"
				:options="datepickerOptions"
				:editable='false'
				@on-change="timeHandleChange"
				@on-clear="timeHandleClear"
				@on-ok="timeHandleOk"
				>
				<div @click="timeHandleClick" style="padding:10px 0;cursor:pointer;">
					<div v-if="processedTime === ''" style="display:flex;"><img style="margin-right:10px;" src="static/image/home/add_processed.png"/>添加日程提醒</div>
					<div v-else style="display:flex;"><img style="margin-right:10px;" src="static/image/home/processed_time.png"/>{{processedTime}}</div>
				</div>
				</Date-picker> -->
    </div>
    <div class="remain_t_f">
      <div class="re_adopt" @click.stop.prevent="addBacklog" v-show="remindStatus != 2">
        确定
      </div>
      <div class="re_refuse" @click.stop.prevent="$emit('update:addProcessedShow',false)">
        取消
      </div>
    </div>
  </div>
</template>
           
<script>
import { addRemind_axios, updateRemindTime_axios } from "../../api/home";
import tools from "@/utils/tools.js";
import JQ from "jquery";
export default {
  props: [
    "addProcessedShow",
    "remindStatus",
    "toInfo",
    "sqlTable",
    "processedItem",
    "myInfo",
  ],
  data() {
    return {
      timeOpen: false,
      processedTime: "",
    };
  },

  methods: {
    timeHandleClear() {
      this.timeOpen = false;
    },
    timeHandleOk() {
      this.timeOpen = false;
    },
    timeHandleChange(date) {
      this.processedTime = date;
    },
    //添加待办
    addBacklog() {
      if (this.processedTime.trim() == "" && this.remindStatus != 2) {
        this.$Message.warning("请选择提醒时间");
        return;
      }
      if (this.remindStatus == 0) {
        let isTrue = this.toInfo.isGroup == "1";
        let str;
        let value = {};
        str = `${
          isTrue ? this.sqlTable.messageList : this.sqlTable.privateList
        } WHERE messageId='${this.processedItem.messageId}'`;
        let res = tools.operationalDatabase(
          `SELECT * FROM  ${str} ORDER BY time DESC;`,
          1
        );
        if (res.list.length > 0) {
          value = res.list[0];
        }
        addRemind_axios({
          from_name: this.toInfo.name,
          type: this.toInfo.isGroup == "1" ? 1 : 0, //文件来源类型 0:单人文件 1:群文件
          message_id: this.processedItem.messageId, //消息id
          user_id: this.myInfo.id,
          file_id: this.processedItem.DownLoadId,
          from_id: this.toInfo.id,
          file_type: this.processedItem.type,
          remind_time: this.processedTime,
          value: value.value,
        })
          .then((res) => {
            if (res.result == 200) {
              this.$emit("getRemind");
              //   this.getRemind();
              this.$Message.success("添加待办成功");
            } else {
              this.$Message.warning(res.msg);
            }
          })
          .catch((error) => {
            this.$Message.warning("服务器出错,稍后再试20");
          });
      } else if (this.remindStatus == 1) {
        updateRemindTime_axios({
          remindid: this.processedItem.ID,
          time: this.processedTime,
        })
          .then((res) => {
            if (res.result == 200) {
              this.$set(this.processedItem, "REMIND_TIME", this.processedTime);
              this.$emit("getRemind");
              //   this.getRemind();
              this.$Message.success("修改成功");
            } else {
              this.$Message.warning(res.msg);
            }
          })
          .catch((error) => {
            this.$Message.warning("服务器出错,稍后再试21");
          });
      }
      this.$emit("update:addProcessedShow", false);
      //   this.addProcessedShow = false;
    },
    //待办时间事件
    timeHandleClick() {
      // 查看内容时return
      if (this.remindStatus == 2) {
        return;
      }
      JQ(".dxTime ")[0].children[0].focus();
      this.timeOpen = !this.timeOpen;
    },
  },
};
</script>
<style scoped>
</style>